package cn.com.bluemoon.daps.sync.core.sync;

import cn.hutool.core.net.Ipv4Util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jarod.Kong
 */
@Slf4j
public class SandboxUtils {
    private SandboxUtils() {
    }

    /** 生产库名称 用于沙箱 */
    public static String uniqueDbName(String host, Integer port, String databaseName) {
        if (StringUtils.isBlank(databaseName)) {
            return null;
        }
        List<String> sep = new ArrayList<>();
        sep.add(databaseName.toLowerCase());
        if (host != null) {
            String lIp = Ipv4Util.ipv4ToLong(host) + "";
            log.debug("ip to long, {} to {}", host, lIp);
            sep.add(lIp);
        }
        if (port != null) {
            sep.add(port + "");
        }
        return String.join("_", sep);
    }
}
